//
//  ViewController.m
//  03_UIResponder
//
//  Created by dllo on 16/7/18.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    TouchView *touch = [[TouchView alloc] initWithFrame:CGRectMake(10, 50, 300, 200)];
    touch.backgroundColor = [UIColor redColor];
    [self.view addSubview:touch];
    
    // 检测顺序 硬件 -> Appdelegate -> Application -> UIWindow -> self.Window.rootViewController -> self.view -> touchView
    // 响应顺序 touchView -> self.view -> UIViewController -> UIWindow -> UIApplication -> Appdelegate -> null
    // 如果所有响应者都无法响应该事件 则该响应事件被放弃
    // 两种检测响应者的方式
    // 1. Category 实现touchBegin的方法
    // 2. nextResponder
    
    // 例:
    // 1. 响应者不要出界 出便捷的响应者无法响应
    // 2. 系统会判断当前坐标在哪个范围内 由谁来响应
//    BOOL isInsede = [touch pointInside:CGPointMake(10, 50) withEvent:nil]; // 判断该点是否在touch的范围内
//    NSLog(@"%@", isInsede ? @"YES" : @"NO");
    // imageView label 的用户交互默认关闭 (没有响应事件)
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(10, 50, 100, 30);
    button.backgroundColor = [UIColor cyanColor];
    [touch addSubview:button];
    
//    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    // 2. button的点击方法如何实现 (给UIButton 写一个category)
    // button的点击方法 通过UIResponder对应的方法来实现
    // 3. 重写pointInside方法 使响应者失去响应能力
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 60, 30)];
    label.userInteractionEnabled = YES; // 打开用户交互
    label.backgroundColor = [UIColor greenColor];
    [touch addSubview:label];
    
    
    
}

//- (void)click:(UIButton *)button {
//    NSLog(@"%@", button);
//}

// 只要继承与UIResponder 就可以做出响应
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    NSLog(@"%@------%s", [self class], __FUNCTION__);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
